#
require("RPostgreSQL")
require(forecast)
require("tsoutliers")
require(ggplot2)
require("tsintermittent")
library("doParallel")
library("foreach")
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, dbname = "Atotech",
host = "axialyzeproduction.c5drkcatbgmm.eu-central-1.rds.amazonaws.com", port = 8080,
user = "aXialyze", password = "aXialyze0000")
df <- dbGetQuery(con, "SELECT material, cluster, customer_code, totalvolume, ts_categorie, case when sma_only then 1 else 0 end
FROM public.sandop_selection
where not material || customer_code in (select material || left(geography,10) from fcst_accuracy where fcrun = (SeLECT fcrun FROM current_run))
and not (prod_group ilike '1%' and not prod_group = '106' and cluster = 'China') and totalvolume <=1800 and totalvolume > 250
order by totalvolume desc " )
#other option df <- dbGetQuery(con, "SELECT material, cluster, lpad(custdfomer_code,10,'0') customer_code, totalvolume, ts_categorie
#FROM public.sandop_selection
#where not material || lpad(customer_code,10,'0') in (select material || left(geography,10) from fcst_accuracy)
#order by totalvolume desc" )
# Calculate the number of cores
no_cores <- detectCores() - 1
run_mat_cust_mm <- function(df, no_cores) {
foreach(i=1:no_cores) %dopar%
{
require("RPostgreSQL")
require(forecast)
require("tsoutliers")
require(ggplot2)
require("tsintermittent")
source('~/R/aXialyzefcstcontrol/R/main_functions.R')
source('~/R/aXialyzefcstcontrol/R/material_customer.R')
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, dbname = "Atotech",
host = "axialyzeproduction.c5drkcatbgmm.eu-central-1.rds.amazonaws.com", port = 8080,
user = "aXialyze", password = "aXialyze0000")
df2 <- dbGetQuery(con, "SELECT fcrun, to_char(requested_deliv_date_to, 'yyyy-mm-dd') as requested_deliv_date_to, fcperiod FROM public.parameter_sets ps where ps.fcrun = (SeLECT fcrun FROM current_run)" )
batchsize <- floor(nrow(df)/no_cores)
startnr <- batchsize*i - batchsize + 1
if(batchsize*(i+1) > nrow(df)){endnr <- nrow(df) }else {endnr <- batchsize*i}
dfall <- df[startnr:endnr, ]
level <- "material_customer_Continous"
fcrun <- df2[,"fcrun"]
todate <- df2[,"requested_deliv_date_to"] #parameter for last date of history to take into account
fcperiod <- df2[,"fcperiod"]
apply(dfall, 1, f_mat_cust, connection = con, ilevel = level, iYYYY = "YYYY-MM" ,ifreq = 12, fcperiod, TRUE, fcrun, todate)
}}
# Initiate clustertyp
cl <- makeCluster(no_cores)
doParallel::registerDoParallel(cl)
tryCatch(run_mat_cust_mm(df, no_cores), error = function(e) print(e))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.